﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class View_UpdatePage : System.Web.UI.Page
{
    AccessDAO dao = new AccessDAO();
    protected void Page_Load(object sender, EventArgs e)
    {
        IsAdmin.Admin();
        this.btnSubmit.Attributes.Add("onclick", "javascript:succShow();");
        if (!Page.IsPostBack)
        {
            //添加网页类型
            int typeId = Convert.ToInt32(Session["pageTypeId"].ToString());
            string sql = "select * from pageType where id="+typeId;
            DataSet ds = dao.getDs(sql);
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                this.drpItem.Items.Add(dr["typeName"].ToString());
            }

            int id = Convert.ToInt32(Session["pageId"].ToString());
            string sql1 = "select * from pageMessage where id=" + id;
            DataSet ds1 = dao.getDs(sql1);
            foreach (DataRow dr in ds1.Tables["message"].Rows)
            {
                this.txtName.Text = dr["title"].ToString();
                this.FCKeditor1.Value = dr["content"].ToString() ;
            }
        }
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Session["pageId"].ToString());
        int typeId = Convert.ToInt32(Session["pageTypeId"].ToString());
        string title = this.txtName.Text;
        string content= this.FCKeditor1.Value;

        string sql = "update pageMessage set typeId="+typeId+",title='"+title+"',content='"+content+"' where id="+id;
        if (dao.getComm(sql) != 0)
        {
            Server.Transfer("pageMessage1.aspx");
        }
        else
        { 
            RegisterStartupScript("check", "<script language='javascript'>alert('修改失败');</script>");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        Server.Transfer("pageMessage1.aspx");
    }
}
